package com.lesson;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;


/**
 * 初始化器.channel注册后,会执行里面的初始化方法
 * @author liliang
 * @date 2019/10/25.
 */
public class HelloServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel  channel) throws Exception {
        // 通过 SocketChannel去获取 pipeline
        ChannelPipeline pipeline = channel.pipeline();
        // 通过管道添加 handler
        // HttpServerCodec是 netty提供的助手类,用户处理 Http 请求
        pipeline.addLast("HttpServerCodec", new HttpServerCodec());
        pipeline.addLast("customHandler", new CustomHandler());
    }

}
